home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / insight / plugins / mystdvar.pro < prev    next >
Text File  |  1997-07-08  |  12KB  |  356 lines

  1. ; $Id: mystdvar.pro,v 1.9 1997/04/22 17:12:33 rob Exp $
  2. ;
  3. ; Copyright (c) 1997, Research Systems, Inc.  All rights reserved.
  4. ;   Unauthorized reproduction prohibited.
  5. ;+
  6. ; FILE:
  7. ;       mystdvar.pro
  8. ;
  9. ; PURPOSE:
  10. ;       This file contains an Analysis PlugIn that computes Standardized
  11. ;       Variables of a 2D array.
  12. ;
  13. ; CONTENTS:
  14. ;       GENERAL ROUTINES
  15. ;           pro HandleEventsMyStdVar    - handle dialog box events
  16. ;
  17. ;       CALLBACK ROUTINES
  18. ;           fun ApplyMyStdVar           - Apply/OK entry point
  19. ;           fun PromptUserMyStdVar      - main entry point (creates dialog)
  20. ;
  21. ;       REGISTRATION FUNCTION
  22. ;           fun MyStdVar                - registers the PlugIn
  23. ;
  24. ;-
  25.  
  26. FORWARD_FUNCTION STANDARDIZE
  27.  
  28. ; *****************************************************************************
  29. ;       GENERAL ROUTINES
  30. ; *****************************************************************************
  31.  
  32. ; -----------------------------------------------------------------------------
  33. ;
  34. ;   Purpose:  Handle dialog events.
  35. ;
  36. pro HandleEventsMyStdVar, sEvent
  37.  
  38.     ;  Widget state information.
  39.     ;
  40.     common MyStdVarCommon, psState
  41.     wGroup = (*psState).wMainBase
  42.  
  43.     ;  Catch errors.
  44.     ;
  45.     CATCH, error
  46.     if (error ne 0) then begin
  47.         CATCH, /CANCEL
  48.         void = DIALOG_MESSAGE(!ERR_STRING, DIALOG_PARENT=wGroup)
  49.         RETURN
  50.     endif
  51.  
  52.     ; ========================
  53.     ;     PROCESS EVENTS
  54.     ; ========================
  55.  
  56.     case (sEvent.id) of
  57.  
  58.         ; --------------------------------------
  59.         ;     Input text
  60.         ; --------------------------------------
  61.         (*psState).wInputText: begin
  62.  
  63.             ; (nothing to do now)
  64.  
  65.         end
  66.  
  67.         ; --------------------------------------
  68.         ;     Input browse button
  69.         ; --------------------------------------
  70.         (*psState).wInputBrowseButton: begin
  71.  
  72.             ;  Let user browser for a data name.
  73.             ;
  74.             void = INSGET( $
  75.                 NAME=inputName, $           ; returned name of data selected
  76.                 /EXCLUSIVE, $               ; only one selection
  77.                 TITLE='Select an array.', $ ; title of browser
  78.                 DIMS_LIST=2, $              ; show 2D array data only
  79.                 COUNT=count, $              ; returned count of items selected
  80.                 GROUP=wGroup, $             ; widget group leader
  81.                 _EXTRA=(*psState).extra)    ; extra information
  82.  
  83.             ;  If user selected an item, set data name in text widget.
  84.             ;
  85.             if (count eq 1) then $
  86.                 WIDGET_CONTROL, (*psState).wInputText, SET_VALUE=inputName
  87.  
  88.         end
  89.  
  90.         ; --------------------------------------
  91.         ;     Std. Variables (column or row) bgroup
  92.         ; --------------------------------------
  93.         (*psState).wStdVarBgroup: begin
  94.  
  95.             WIDGET_CONTROL, (*psState).wStdVarBgroup, GET_VALUE=value
  96.  
  97.             if (value eq 0) then $
  98.                 (*psState).StdVarOrient = 0 $
  99.             else if (value eq 1) then $
  100.                 (*psState).StdVarOrient = 1 
  101.  
  102.         end
  103.  
  104.         ; --------------------------------------
  105.         ;     OK/Apply/Cancel buttons
  106.         ; --------------------------------------
  107.         (*psState).wOKApplyCancelButtons: begin
  108.  
  109.             ;  Destroy dialog on successful OK selection, or if user canceled.
  110.             ;
  111.             if ((sEvent.type eq 'OK') or $
  112.                 (sEvent.type eq 'Cancel')) then $
  113.                 WIDGET_CONTROL, (*psState).wMainBase, /DESTROY
  114.         end
  115.  
  116.         ; --------------------------------------
  117.         ;     other events
  118.         ; --------------------------------------
  119.         else:   ; (do nothing)
  120.  
  121.     endcase
  122.  
  123. end                 ; HandleEventsMyStdVar
  124.  
  125. ; *****************************************************************************
  126. ;       CALLBACK ROUTINES
  127. ; *****************************************************************************
  128.  
  129. ; -----------------------------------------------------------------------------
  130. ;
  131. ;   Purpose:  Get data and StdVar it.
  132. ;             Fuction returns 1B on success, else 0B.
  133. ;
  134. function ApplyMyStdVar, $
  135.     CIDs=CIDs, $        ; OUT: command ID list from INSPUT/INSVIS calls
  136.     _EXTRA=extra        ; IN: information to pass to commands
  137.  
  138.     ;  Widget state information.
  139.     ;
  140.     common MyStdVarCommon, psState
  141.     wGroup = (*psState).wMainBase
  142.  
  143.     ; ---------------------------------------------------------
  144.     ;  Catch errors.
  145.     ; ---------------------------------------------------------
  146.  
  147.     CATCH, error
  148.     if (error ne 0) then begin
  149.         CATCH, /CANCEL
  150.         void = DIALOG_MESSAGE(!ERR_STRING, DIALOG_PARENT=wGroup)
  151.         RETURN, 0B
  152.     endif
  153.  
  154.     ; ---------------------------------------------------------
  155.     ;  Check inputs.
  156.     ; ---------------------------------------------------------
  157.  
  158.     ;  Get and check input data name.
  159.     ;
  160.     WIDGET_CONTROL, (*psState).wInputText, GET_VALUE=inputName
  161.     inputName = inputName[0]
  162.     if (inputName eq '') then $
  163.         MESSAGE, 'Must specify input data.'
  164.  
  165.     ;  Get input data.
  166.     ;
  167.     inputData = INSGET( $
  168.         inputName, $                ; name of data to get
  169.         COUNT=count, $              ; returned number of items found
  170.         DIMS_LIST=2, $              ; data should have this dimensionality
  171.         GROUP=wGroup, $             ; widget group leader
  172.         _EXTRA=extra)               ; extra information
  173.  
  174.     ;  Return if data not found (INSGET displays own error messages).
  175.     ;
  176.     if (count ne 1) then $
  177.         RETURN, 0B
  178.  
  179.     ; ---------------------------------------------------------
  180.     ;  Compute Standardized Variables.
  181.     ; ---------------------------------------------------------
  182.  
  183.     if ((*psState).StdVarOrient eq 0) then $        ; Standardize by column.
  184.         newData = STANDARDIZE(inputData) $
  185.     else $                                          ; Standardize by row.
  186.         newData = TRANSPOSE(STANDARDIZE(TRANSPOSE(inputData)))
  187.  
  188.     ; ---------------------------------------------------------
  189.     ;  Put the new data into Insight (Data Manager)
  190.     ; ---------------------------------------------------------
  191.  
  192.     description = 'Standardized ' + inputName
  193.  
  194.     outputName = (*psState).outputName
  195.  
  196.     INSPUT, $
  197.         newData, $                      ; the data
  198.         DESCRIPTION=description, $      ; data description
  199.         NAME=outputName, $              ; try this data name
  200.         NEW_NAME=outputNameUsed, $      ; the data name actually used
  201.         REPLACE=2, $                    ; prompt user if name conflict
  202.         COUNT=count, $                  ; returned # of items put
  203.         CIDs=CIDs, $                    ; command ID list
  204.         GROUP=wGroup, $                 ; widget group leader
  205.         _EXTRA=extra                    ; extra information
  206.  
  207.     ;  Return if "put" failed.
  208.     ;
  209.     if (count ne 1) then $
  210.         RETURN, 0B
  211.  
  212.     ; ---------------------------------------------------------
  213.     ;  Visualize new data item.
  214.     ; ---------------------------------------------------------
  215.  
  216.     INSVIS, $
  217.         outputNameUsed, $   ; name of data item
  218.         TYPE='surface', $   ; visualization type
  219.         MODE='new', $       ; insert | new | overlay
  220.         CIDs=CIDs, $        ; command ID list
  221.         GROUP=wGroup, $     ; widget group leader
  222.         _EXTRA=extra        ; extra information
  223.  
  224.     ; ---------------------------------------------------------
  225.     ;  Successful return.
  226.     ; ---------------------------------------------------------
  227.  
  228.     RETURN, 1B
  229.  
  230. end                 ; ApplyMyStdVar
  231.  
  232. ; -----------------------------------------------------------------------------
  233. ;
  234. ;   Purpose:  Main entry point for the PlugIn.
  235. ;
  236. pro PromptUserMyStdVar, $
  237.     GROUP=wGroup, $     ; IN: group leader widget ID
  238.     _EXTRA=extra        ; IN: various information
  239.  
  240.     ;  Widget state information.
  241.     ;
  242.     common MyStdVarCommon, psState
  243.  
  244.     ;  Create modal main base (non-sizable).
  245.     ;
  246.     title = 'Analysis PlugIn - Standardized Variables'
  247.     wMainBase = WIDGET_BASE(TITLE=title, GROUP_LEADER=wGroup, $
  248.         /COLUMN, /MODAL, /TLB_FRAME_ATTR)
  249.  
  250.     value = [ $
  251.         'Select a 2D array to compute Standardized Variables.', $
  252.         'Standardized Variables are a prerequisite to most', $
  253.         'types of multivariate statistical analysis.', $ 
  254.         'Output is displayed as a surface and is available', $
  255.                 'through the Data Manager.' $
  256.         ]
  257.     for i = 0, N_ELEMENTS(value)-1 do $
  258.         void = WIDGET_LABEL(wMainBase, VALUE=value[i])
  259.  
  260.     ; ------------------------------------------
  261.     ;  Create INPUTS widgets.
  262.     ; ------------------------------------------
  263.  
  264.     wInputsBase = WIDGET_BASE(wMainBase, /COLUMN, /FRAME)
  265.  
  266.     void = WIDGET_LABEL(wInputsBase, VALUE='INPUTS')
  267.  
  268.     wInputDataBase = WIDGET_BASE(wInputsBase, /ROW)
  269.     void = WIDGET_LABEL(wInputDataBase, VALUE='Input: ')
  270.     wInputText = WIDGET_TEXT(wInputDataBase, VALUE='', /EDITABLE)
  271.     wInputBrowseButton = WIDGET_BUTTON(wInputDataBase, VALUE=' Browse... ')
  272.  
  273.     wStdVarBase = WIDGET_BASE(wInputsBase, /ROW)
  274.     void = WIDGET_LABEL(wStdVarBase, VALUE='Orientation: ')
  275.     wStdVarBgroup = CW_BGROUP(wStdVarBase, ['By Column', 'By Row'], $
  276.         /NO_RELEASE, /ROW, /RETURN_NAME, /EXCLUSIVE, SET_VALUE=0)
  277.     StdVarOrient = 0
  278.  
  279.     ; ------------------------------------------
  280.     ;  Create OUTPUTS widgets.
  281.     ; ------------------------------------------
  282.  
  283.     outputName = 'Standardized Output'
  284.  
  285.     wOutputsBase = WIDGET_BASE(wMainBase, /ROW, /FRAME)
  286.     void = WIDGET_LABEL(wOutputsBase, VALUE='                   ')
  287.  
  288.     wOutputsLabelBase = WIDGET_BASE(wOutputsBase, /COLUMN)
  289.     void = WIDGET_LABEL(wOutputsLabelBase, VALUE='OUTPUTS')
  290.     void = WIDGET_LABEL(wOutputsLabelBase, VALUE='Output:  '+outputName)
  291.  
  292.     ; ------------------------------------------
  293.  
  294.     ;  Create OK/Apply/Cancel buttons using special compound widget.
  295.     ;  (Must pass in main modal base, used to set default and cancel buttons.)
  296.     ;
  297.     wOKApplyCancelButtons = CW_INSAPPLY(wMainBase, _EXTRA=extra)
  298.  
  299.     ;  Create dialog state information.
  300.     ;
  301.     sState = { $
  302.         extra: extra, $
  303.         wMainBase: wMainBase, $
  304.         outputName: outputName, $
  305.         wInputText: wInputText, $
  306.         wInputBrowseButton: wInputBrowseButton, $
  307.         wStdVarBgroup: wStdVarBgroup, $
  308.         StdVarOrient: StdVarOrient, $
  309.         wOKApplyCancelButtons: wOKApplyCancelButtons $
  310.         }
  311.  
  312.     ;  Store the state in a heap variable.
  313.     ;
  314.     psState = PTR_NEW(sState, /NO_COPY)
  315.  
  316.     ;  Realize the dialog box.
  317.     ;
  318.     WIDGET_CONTROL, wMainBase, /REALIZE
  319.  
  320.     ;  Start event loop.
  321.     ;
  322.     XMANAGER, 'PromptUserMyStdVar', wMainBase, $
  323.         EVENT_HANDLER='HandleEventsMyStdVar'
  324.  
  325.     ;  Remove widget state info.
  326.     ;
  327.     PTR_FREE, psState
  328.  
  329. end                 ; PromptUserMyStdVar
  330.  
  331. ; *****************************************************************************
  332. ;       REGISTRATION FUNCTION
  333. ; *****************************************************************************
  334.  
  335. ; -----------------------------------------------------------------------------
  336. ;
  337. ;   Purpose:  Register the Analysis PlugIn.
  338. ;
  339. function MyStdVar
  340.  
  341.     ;  Return the Analysis PlugIn Registration Structure.
  342.     ;
  343.     RETURN, { $
  344.         type:       'Analysis_PlugIn', $            ; PlugIn type
  345.         title:      'My StdVar...', $               ; PlugIn title
  346.         purpose:    'Compute standardized variables.', $ ; PlugIn purpose
  347.         main_proc:  'PromptUserMyStdVar', $         ; main callback
  348.         apply_func: 'ApplyMyStdVar', $              ; apply callback
  349.         version:    '5.0', $                        ; IDL version
  350.         revision:   '1.0' $                         ; PlugIn version
  351.         }
  352.  
  353. end                 ; MyStdVar
  354.  
  355. ; -----------------------------------------------------------------------------
  356.